package com.leo.controller;

import com.leo.base.utils.QrcodeGeneratorUtils;
import de.felixroske.jfxsupport.FXMLController;
import de.felixroske.jfxsupport.GUIState;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName LoginController
 * @Description
 * @Author wangss
 * @date 2020.11.16 11:45
 * @Version 1.0
 */
@Slf4j
@FXMLController
public class LoginController {

    public AnchorPane mainView;

    public void close(ActionEvent actionEvent) {
        Platform.runLater(() -> {
            GUIState.getStage().close();
        });
        Platform.exit();
    }

    public void set(ActionEvent actionEvent) {

    }

    public void login(ActionEvent actionEvent) {

    }

    public void changeUser(MouseEvent mouseEvent) {

        try {
            // 移除所有的元素
            mainView.getChildren().removeAll(mainView.getChildren());

            // 生成二维码
            ImageView imageView = QrcodeGeneratorUtils.generatorQRCodeImageFx("请使用手机扫码登录", 236, 236);
            imageView.setLayoutX(57.0);
            imageView.setLayoutY(90.0);
            imageView.setPreserveRatio(true);
            imageView.setPickOnBounds(true);
            // 说明
            Label label = new Label("请使用手机扫描登录");
            label.setTextFill(Paint.valueOf("#a49999"));
            label.setFont(Font.font(20.0));
            label.setLayoutX(85.0);
            label.setLayoutY(360.0);
            // 添加组件
            mainView.getChildren().addAll(imageView, label);
        } catch (Exception e) {
            log.error("二维码生成失败:[{}]", e.getMessage());
        }
    }
}
